/*
 * Copyright (c) 2008, Ramiro Espada and Jorge Hernandez
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
import org.molamil.cascada.selector.MemberSelector;

import asunit.framework.TestCase;
 
/**
 * @author Jorge Hernandez and Ramiro Espada
 */
class org.molamil.cascada.selector.MemberSelectorTest extends TestCase {
	
	
	private var className:String = "org.molamil.cascada.selector.MemberSelectorTest";
	private var instance:MemberSelector;

	
	public function setUp():Void {
		instance = new MemberSelector();
	}

	public function tearDown():Void {
		delete instance;
	}

	public function testInstantiated():Void {
		assertTrue("MemberSelector instantiated", instance instanceof MemberSelector);
	}
	
	public function testSelect():Void {
		
		// First test set - testing standard selection on a dynamic object.
		var o1:Object = {s: "s", n: 1};
		o1.b1 = true;		o1.b2 = true;
		o1.d = new Date();
		o1.f1 = function():Void {
			trace("f1");
		};
		o1.f2 = oLength;
		o1.a = [1, 2, 3];		o1.nn = null;
		
		var result1:Object;
		var selector1:MemberSelector = new MemberSelector();
		selector1.input = o1;
		result1 = selector1.select();
		
		assertTrue("o1 9 elements", oLength(result1) == 9);		assertTrue("o1 b1 == true", result1.b1 == true);		assertTrue("o1 b2 == true", result1.b2 == true);		assertTrue("o1 d instanceof Date", result1.d instanceof Date);		assertTrue("o1 typeof(f1) == function", typeof(result1.f1) == "function");		assertTrue("o1 typeof(f2) == function", typeof(result1.f2) == "function");		assertTrue("o1 f2 == oLength", result1.f2 == oLength);		assertTrue("o1 a.length == 3", result1.a.length == 3);		assertTrue("o1 a.nn == null", result1.nn == null);
		
	}
	
	private function oLength(o:Object):Number {
		var n:Number = 0;
		for (var p:String in o)
			n++;
		return n;
	}
	
}
